public with sharing class PageRedirectController {
//public PageRedirectController(ApexPages.StandardController controller) {}
      public Activity_Information__c ActivityInit{get;set;}
       public pageReference pr{get;set;}
       public CommonMethod getCommonMethod;

    public PageRedirectController(ApexPages.StandardController controller) {
        ActivityInit=[Select Id,Name,OwnerId,Activity_End_Date__c, Activity_Notice__c, Activity_Stage__c, Activity_Start_Date__c, 
                             Activity_Type_State__c, Activity_Type__c, DM_End_Date__c, DM_Start_Date__c, Display_End_Date__c, 
                             Display_Start_Date__c,Serial_Number__c,Regional_Activity_Type__c FROM Activity_Information__c where id=: RecordId];          
         Redirect(); 
    }
    //RecordId
 public String RecordId
   {
       get
       {
           return String.valueOf(System.currentPageReference().getParameters().get('id')).substring(0,15);  
       }
       set;
   }
public PageReference Redirect() {
      getCommonMethod=new CommonMethod();
      pr = new pageReference('/'+RecordId);       
      User user=getCommonMethod.getUserInfo();//ASM/DSM  

    if(user.Title__c=='Sales Rep'){
          pr = new pageReference('/apex/TSRResourceAjustmnet?id='+RecordId);     //跳转到ASM
         }  
      
     if(ActivityInit.Activity_Type__c=='SSY')
     {
         
         if(user.Title__c=='Area/District Sales Manager')
         {
              boolean flag=true;
              for(ParticipatorArea__c p:[select  OT_Status__c from ParticipatorArea__c where Activity_Name__c=:RecordId and Region__c=:user.UserRegion__c]){
                        if(p.OT_Status__c!='SRTM已提交'){
                            flag=false;
                            break; 
                          }
                  }
                    if(flag==true){
                     pr = new pageReference('/apex/SSYASMResourceAjustmnet?id='+RecordId);     //跳转到ASM
                    }
         }
         else if(user.Title__c=='Functional')
         {
             if(user.Title_Functional__c=='NTMKT')
             {
                pr = new pageReference('/apex/InitActivityForNTMKTList?id='+RecordId);     //跳转到总部
                return pr;
              }
              else if(user.Title_Functional__c=='KAM')
              {
                  if(ActivityInit.Activity_Stage__c=='总部已发起活动')
                       pr = new pageReference('/apex/SSYKAResourceAllcation?id='+RecordId);     //跳转到KAM
              }
              else if(user.Title_Functional__c=='SRTM')
              {
                   boolean flag=true;
                   for(ParticipatorArea__c p:[select  KA_Status__c from ParticipatorArea__c where Activity_Name__c=:RecordId and Type__c='KA']){
                        if(p.KA_Status__c!='已审批'){
                            flag=false;
                            break; 
                          }
                      }
                    if(flag==true){
                         pr = new pageReference('/apex/SSYOTResourceAllcation?id='+RecordId);     //跳转到SRTM
                    }
                }  
    }
   }else if(ActivityInit.Activity_Type__c=='KA'){
         if(user.Title__c=='Area/District Sales Manager'){
             boolean flag=true;
                   for(ParticipatorArea__c p:[select  KA_Status__c from ParticipatorArea__c where Activity_Name__c=:RecordId]){
                        if(p.KA_Status__c!='已审批'){
                            flag=false;
                            break; 
                          }
                      }
                    if(flag==true){
                    pr = new pageReference('/apex/KAASMResourceAjustmnet?id='+RecordId+'&&ActivityType='+ActivityInit.Activity_Type__c);     //跳转到ASM
                    }
         }else if(user.Title__c=='Functional'){
             if(user.Title_Functional__c=='NTMKT'){
                pr = new pageReference('/apex/KAInitActivityForNTMKTList?id='+RecordId+'&&ActivityType='+ActivityInit.Activity_Type__c);  //跳转到总部
              }else if(user.Title_Functional__c=='KAM'){
                 if(ActivityInit.Activity_Stage__c=='总部已发起活动'){
                       pr = new pageReference('/apex/KAForKAResourceAllcation?id='+RecordId);  //跳转到KAM
                   }
              }    
        }
   }else if(ActivityInit.Activity_Type__c=='Region'){
      if(user.Title__c=='Functional'){
           if(user.Title_Functional__c=='SRTM' || user.Title_Functional__c=='RTM'){
                pr = new pageReference('/apex/KAInitActivityForNTMKTList?id='+RecordId+'&&ActivityType='+ActivityInit.Activity_Type__c);     //跳转到总部
            }
      }else if(user.Title__c=='Area/District Sales Manager'){
          //两者兼无情况
           if(ActivityInit.Activity_Stage__c=='SRTM已发起活动' && ActivityInit.Regional_Activity_Type__c=='竞品活动')
               pr = new pageReference('/apex/KAASMResourceAjustmnet?id='+RecordId+'&&ActivityType='+ActivityInit.Activity_Type__c);     //跳转到ASM
           if(ActivityInit.Activity_Stage__c=='SRTM已完成区域调整')
               pr = new pageReference('/apex/KAASMResourceAjustmnet?id='+RecordId+'&&ActivityType='+ActivityInit.Activity_Type__c);     //跳转到ASM
         }
      }else if(ActivityInit.Activity_Type__c=='Region(剩余资源)'){
         if(user.Title__c=='Functional'){
           if(user.Title_Functional__c=='SRTM' || user.Title_Functional__c=='RTM'){
                pr = new pageReference('/apex/InitRegionRemainderActivity?id='+RecordId);     //跳转到总部
            }
        }else if(user.Title__c=='Area/District Sales Manager'){
             if(ActivityInit.Activity_Stage__c=='SRTM已发起活动' )
                  pr = new pageReference('/apex/KAASMResourceAjustmnet?id='+RecordId+'&&ActivityType='+ActivityInit.Activity_Type__c);     //跳转到ASM
        }
      }
    pr.setRedirect(true);   
    return pr;
}
}